package com.ekalenchuk.module.service.secutiry;

import java.util.Collection;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

public class CustomUserAuthentication implements Authentication {
	private static final long serialVersionUID = -502537970729946710L;
	private String name;
	private Object details;
	private UserDetails user;
	private boolean authenticated;
	private Collection<? extends GrantedAuthority> authorities;

	public CustomUserAuthentication(UserDetails user, Object details) {
		this.name = user.getUsername();
		this.details = details;
		this.user = user;
		this.authorities = user.getAuthorities();
		authenticated = true;
	}

	public String getName() {
		return name;
	}

	public Collection<? extends GrantedAuthority> getAuthorities() {
		return authorities;
	}

	public Object getCredentials() {
		return user.getPassword();
	}

	public Object getDetails() {
		return details;
	}

	public Object getPrincipal() {
		return user;
	}

	public boolean isAuthenticated() {
		return authenticated;
	}

	public void setAuthenticated(boolean authenticated) throws IllegalArgumentException {
		this.authenticated = authenticated;
	}
}
